package MelbourneMap;

/**
 * Edge object used to represent an edge between
 * two {@link Node} objects in a {@link Graph}.
 * An edge contains both the from Node and to 
 * Node for this edge.
 * <p>
 * Contains the cost of the edge between the nodes. 
 * 
 * @author David Zappia, 7183216
 * @author Heong Jin Yu, 7019777
 *
 */
public class Edge 
{
	private Node from, to;
	private double cost;
	
	/**
	 * Constructor for an edge. Takes a node from which this edge
	 * began and the node to which this edge goes.
	 * 
	 * @param fromNode		the node from where this edge began
	 * @param toNode		the node to which this node goes
	 */
	public Edge(Node fromNode, Node toNode)
	{
		from = fromNode;
		to = toNode;
		calcCost();
	}
	
	/**
	 * Gets the node from which this edge begins.
	 * 
	 * @return		the node from which this node begins
	 */
	public Node getFrom()
	{
		return from;
	}
	
	/**
	 * Gets the node to which this edge goes.
	 * 
	 * @return		the node to which this node goes
	 */
	public Node getTo()
	{
		return to;
	}
	
	/**
	 * Calculates the traversal cost relating to
	 * this edge. Based on straight line distance.
	 */
	public void calcCost()
	{
		double x = to.getX() - from.getX();
		double y = to.getY() - from.getY();
		cost =  (x*x) + (y*y);
	}
	
	/**
	 * Gets the traversal cost relating to this edge.
	 * 
	 * @return		the cost of this edge
	 */
	public double getCost()
	{
		return cost;
	}
}
 